{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# MTH 9879 Market Microstructure Models,    Spring 2015 \n",
    "\n",
    "## Lecture 10: Optimal trading strategies: Transient market impact\n",
    "\n",
    "Tai-Ho Wang    \n",
    "Department of Mathematics   \n",
    "  \n",
    "  \n",
    "<h2><img src=\"http://mfe.baruch.cuny.edu/wp-content/uploads/2014/09/BCCUNYstacked_BLK.jpg\" align = \"center\" width=160></h2>  \n",
    "\n",
    "$$\n",
    "\\newcommand{\\bea}{\\begin{eqnarray}}\n",
    "\\newcommand{\\eea}{\\end{eqnarray}}\n",
    "\\newcommand{\\supp}{\\mathrm{supp}}\n",
    "\\newcommand{\\F}{\\mathcal{F} }\n",
    "\\newcommand{\\cF}{\\mathcal{F} }\n",
    "\\newcommand{\\E}{\\mathbb{E} }\n",
    "\\newcommand{\\Eof}[1]{\\mathbb{E}\\left[ #1 \\right]}\n",
    "\\def\\Cov{{ \\mbox{Cov} }}\n",
    "\\def\\Var{{ \\mbox{Var} }}\n",
    "\\newcommand{\\1}{\\mathbf{1} }\n",
    "\\newcommand{\\p}{\\partial}\n",
    "\\newcommand{\\PP}{\\mathbb{P} }\n",
    "\\newcommand{\\Pof}[1]{\\mathbb{P}\\left[ #1 \\right]}\n",
    "\\newcommand{\\QQ}{\\mathbb{Q} }\n",
    "\\newcommand{\\R}{\\mathbb{R} }\n",
    "\\newcommand{\\DD}{\\mathbb{D} }\n",
    "\\newcommand{\\HH}{\\mathbb{H} }\n",
    "\\newcommand{\\spn}{\\mathrm{span} }\n",
    "\\newcommand{\\cov}{\\mathrm{cov} }\n",
    "\\newcommand{\\HS}{\\mathcal{L}_{\\mathrm{HS}} }\n",
    "\\newcommand{\\Hess}{\\mathrm{Hess} }\n",
    "\\newcommand{\\trace}{\\mathrm{trace} }\n",
    "\\newcommand{\\LL}{\\mathcal{L} }\n",
    "\\newcommand{\\s}{\\mathcal{S} }\n",
    "\\newcommand{\\ee}{\\mathcal{E} }\n",
    "\\newcommand{\\ff}{\\mathcal{F} }\n",
    "\\newcommand{\\hh}{\\mathcal{H} }\n",
    "\\newcommand{\\bb}{\\mathcal{B} }\n",
    "\\newcommand{\\dd}{\\mathcal{D} }\n",
    "\\newcommand{\\g}{\\mathcal{G} }\n",
    "\\newcommand{\\half}{\\frac{1}{2} }\n",
    "\\newcommand{\\T}{\\mathcal{T} }\n",
    "\\newcommand{\\bit}{\\begin{itemize}}\n",
    "\\newcommand{\\eit}{\\end{itemize}}\n",
    "\\newcommand{\\beq}{\\begin{equation}}\n",
    "\\newcommand{\\eeq}{\\end{equation}}\n",
    "\\newcommand{\\tr}{\\mbox{tr}}\n",
    "\\newcommand{\\underbar}{\\underline}\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Outline of Lecture 10\n",
    "\n",
    "-   The order book model of Obizhaeva and Wang\n",
    "\n",
    "\n",
    "-   The model of Alfonsi, Fruth and Schied\n",
    "\n",
    "\n",
    "-   What choices of decay kernel $G(\\cdot)$ preclude price manipulation\n",
    "    when instantaneous market impact $f(\\cdot)$ is linear?\n",
    "\n",
    "\n",
    "-   Closed-form examples of optimal strategies\n",
    "\n",
    "\n",
    "-   Nonlinear transient market impact\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Overview of execution algorithm design\n",
    "\n",
    "Typically, an execution algorithm has three layers:\n",
    "\n",
    "-   The macrotrader\n",
    "\n",
    "    -   This highest level layer decides how to slice the order: when\n",
    "        the algorithm should trade, in what size and for roughly how\n",
    "        long.\n",
    "\n",
    "\n",
    "-   The microtrader\n",
    "\n",
    "    -   Given a slice of the order to trade (a child order), this level\n",
    "        decides whether to place market or limit orders and at what\n",
    "        price level(s).\n",
    "\n",
    "\n",
    "-   The smart order router\n",
    "\n",
    "    -   Given a limit or market order, which venue should this order be\n",
    "        sent to?\n",
    "\n",
    "In this lecture, we are again concerned with the highest level of the\n",
    "algorithm: How to slice the order.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Statement of the problem\n",
    "\n",
    "-   <span> Given a model for the evolution of the stock price, we would\n",
    "    like to find an optimal strategy for trading stock, the strategy\n",
    "    that minimizes some cost function over all permissible strategies.\n",
    "    </span>\n",
    "\n",
    "    -   <span>We will specialize to the case of stock liquidation where\n",
    "        the initial position $x_0=X$ and the final position\n",
    "        $x_T=0$.</span>\n",
    "\n",
    "\n",
    "-   <span>A <span>*static*</span> strategy is one determined in advance\n",
    "    of trading.</span>\n",
    "\n",
    "\n",
    "-   <span>A <span>*dynamic*</span> strategy is one that depends on the\n",
    "    state of the market during execution of the order, *i.e.* on the\n",
    "    stock price.</span>\n",
    "\n",
    "    -   <span>Delta-hedging is an example of a dynamic strategy. VWAP is\n",
    "        an example of a static strategy.</span>\n",
    "\n",
    "\n",
    "-   <span>It will turn out, surprisingly, that in many models, a\n",
    "    statically optimal strategy is also dynamically optimal.</span>\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### P&L and cost of trading of a trading strategy\n",
    "\n",
    "Let $x_t$ be a trading strategy. The corresponding P&L (up to time $t$), denoted by $\\Pi_t(x)$, is identified as \n",
    "\n",
    "$$\n",
    "\\Pi_t(x) := x_t (S_t - S_0) + \\int_0^t (S_0 - \\tilde S_\\tau) d x_\\tau.\n",
    "$$\n",
    "\n",
    "- The first term represents the (fair) value of stock shares that are yet to be transacted.\n",
    "\n",
    "- The second term corresponds to the monetary value collected from the shares that have been transacted up to time t.\n",
    "\n",
    "- Obviously, should there be no trade in the time interval $[0,t]$, i.e., $x_s = X$ for all $s \\in [0,t]$, the P&L reads $\\Pi_t(x) = X (S_t - S_0)$; reflecting the P&L from the price movement of the stock.\n",
    "\n",
    "#### <font color=blue>Implementation shortfall as cost of trading </font>\n",
    "\n",
    "Negative P&L is also referred to as the *implementation shortfall*, which will be used as the cost of trading, denoted by $C$ hereafter.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Gatheral's transient impact model\n",
    "\n",
    "The price process assumed in [Gatheral]<sup id=\"cite_ref-Gatheral\" class=\"reference\"><a href=\"#cite_note-Gatheral\"><span>[</span>4<span>]</span></a></sup> is\n",
    "\n",
    "$$S_t = S_0 + \\int_0^t\\,h(v_s)\\,G(t-s)\\,ds+M_t, \\quad \\mbox{ where } M_t \\mbox{ is a zero mean martingale/noise.}$$\n",
    "\n",
    "\n",
    "- $h(v_s)$ is referred to as the *instantaneous market impact function*, which represents the impact of trading at time $s$, and $G(t-s)$ is a decay factor. Note that $h(v) > 0$ if $v > 0$; whereas $h(v) < 0$ if $v < 0$. \n",
    "\n",
    "\n",
    "- $S_t$ follows an arithmetic random walk (Brownian motion) with a drift that depends on the accumulated impacts of previous trades.\n",
    "\n",
    "\n",
    "- The cumulative impact of (others’) trading is implicitly in $S_0$ and the noise term.\n",
    "\n",
    "\n",
    "- The model is a generalization of processes due to Almgren, Bouchaud, and Obizhaeva and Wang.\n",
    "\n",
    "\n",
    "- The model corresponds to the “autogressive model” or “propagator model” of Bouchaud et al.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### P&L and cost of trading in Gatheral's transient impact model\n",
    "\n",
    "Note that, at the end of execution period $T$, the P&L reads\n",
    "$$\n",
    "  \\Pi_T(x) = x_T (S_T - S_0) + \\int_0^T (S_0 - \\tilde S_u) d x_u,\n",
    "$$\n",
    "should there be $x_T$ shares yet to be transacted. Hence, in Gatheral's model (note that $\\tilde S_t = S_t$)\n",
    "\n",
    "\\begin{eqnarray*}\n",
    "\\Pi_T(x) &=& x_T (S_T - S_0) + \\int_0^T (S_0 - \\tilde S_u) d x_u \\\\\n",
    "&=& - \\int_0^T \\int_0^t h(v_u)G(t-u) du d x_t - \\int_0^T M_t d x_t \\quad (\\mbox{since } x_T = 0) \\\\\n",
    "&=& - \\int_0^T \\int_0^t h(v_u)G(t-u) du d x_t - (M_T x_T - M_0 x_0) + \\int_0^T x_t d M_t \\quad (\\mbox{Integration by parts}) \\\\\n",
    "&=& - \\int_0^T \\int_0^t h(v_u)G(t-u) du d x_t + \\int_0^T x_t d M_t \\quad (\\mbox{since } x_T = 0 \\mbox{ and } M_0 = 0).\n",
    "\\end{eqnarray*}\n",
    "Therefore, the expected cost corresponding to the trading strategy $x$ is given by  \n",
    "\\begin{eqnarray*}\n",
    "&& \\E\\left[C_T(x)\\right] = \\E\\left[-\\Pi_T(x)\\right] = \\Eof{\\int_0^T \\int_0^t h(v_u)G(t-u) du d x_t}.\n",
    "\\end{eqnarray*}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### The optimal strategy of a risk neutral trader\n",
    "\n",
    "For a risk neutral trader whose objective is to minimize the cost of trading, the optimal control problem reads \n",
    "\n",
    "\\begin{eqnarray*}\n",
    "&& \\min_{v} \\E\\left[C_T(x)\\right] = \\min_v \\int_0^T \\int_0^t h(v_u)G(t-u) du d x_t,\n",
    "\\end{eqnarray*}\n",
    "\n",
    "where the state variable $x_t$ is driven by $dx_t = -v_t dt$ with the constraints $x_0 = X$ and $x_T = 0$. \n",
    "It is equivalent to a variational problem.\n",
    "\n",
    "\\begin{eqnarray*}\n",
    "&& \\min_{v} \\E\\left[C_T(x)\\right] = \\min_v \\left\\{-\\int_0^T \\int_0^t h(v_u)G(t-u) du v_t dt\\right\\},\n",
    "\\end{eqnarray*}\n",
    "\n",
    "subject to the constraint $\\int_0^T v_t dt = X$.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Lagrange multiplier  \n",
    "\n",
    "To derive the Euler-Lagrange equation, consider the Lagrangian\n",
    "\n",
    "\\begin{eqnarray*}\n",
    "  && L(v,\\lambda) = \\int_0^T\\int_0^t v_t G(t-s) h(v_s) ds dt - \\lambda \\left( \\int_0^T v_t dt - X \\right) \\\\\n",
    "  &=& \\int_0^T \\left[ \\int_0^t G(t-s) h(v_s) ds - \\lambda \\right] v_t dt + \\lambda X,\n",
    "\\end{eqnarray*}\n",
    "\n",
    "where $\\lambda$ is the Lagrange multiplier. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Euler-Lagrange equation\n",
    "\n",
    "Let $\\varphi$ be a perturbation. Consider the first order criterion for the Lagrangian $L$:\n",
    "\n",
    "\\begin{eqnarray*}\n",
    "  0 &=& \\left.\\frac{d}{d\\epsilon}\\right|_{\\epsilon=0} L( v_t + \\epsilon \\varphi_t,\\lambda) \\\\\n",
    "  &=& \\left.\\frac{d}{d\\epsilon}\\right|_{\\epsilon=0} \\int_0^T \\left[ \\int_0^t G(t-s) h(v_s + \\epsilon \\varphi_s) ds - \\lambda \\right] (v_t + \\epsilon \\varphi_t ) dt  \\\\\n",
    "  &=& \\int_0^T \\left[ \\int_0^t G(t-s) h'(v_s) \\varphi_s ds \\right] v_t dt\n",
    "   + \\int_0^T \\left[ \\int_0^t G(t-s) h(v_s) ds - \\lambda \\right] \\varphi_t dt  \\\\\n",
    "  &=& \\int_0^T \\int_0^t G(t-s) h'(v_s) \\varphi_s v_t ds dt + \\int_0^T \\left[ \\int_0^t G(t-s) h(v_s) ds - \\lambda \\right] \\varphi_t dt  \\\\\n",
    "%  &=& \\int_0^T \\int_s^T G(t-s) h'(v_s) \\varphi_s v_t dt ds + \\int_0^T \\left[ \\int_0^t G(t-s) h(v_s) ds + \\lambda \\right] \\varphi_t dt  \\\\\n",
    "  &=& \\int_0^T \\left[ \\int_t^T G(s-t) h'(v_t) v_s ds + \\int_0^t G(t-s) h(v_s) ds - \\lambda \\right] \\varphi_t dt.\n",
    "\\end{eqnarray*}\n",
    "\n",
    "Since $\\varphi_t$ is arbitrary (because the first order criterion must hold for any perturbation), we must have\n",
    "\n",
    "<a name=\"eq:intEL-TH\"></a>(2)\n",
    "<font color=blue>\n",
    "$$\n",
    "  \\int_t^T G(s-t) h'(v_t) v_s ds + \\int_0^t G(t-s) h(v_s) ds = \\lambda \n",
    "$$\n",
    "</font>\n",
    "<br>\n",
    "for all $0 \\leq t \\leq T$. This a generalized Fredholm integral equation of the first kind. The Lagrange multiplier $\\lambda$ is determined by the constraint $\\int_0^T v_t dt = X$."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Obizhaeva and Wang 2005\n",
    "\n",
    "Recall from [Obizhaeva and Wang]<sup id=\"cite_ref-ObizhaevaWang\" class=\"reference\"><a href=\"#cite_note-ObizhaevaWang\"><span>[</span>7<span>]</span></a></sup> that in this model,\n",
    "\n",
    "<a name=\"eq:OWprocess\"></a>(1)\n",
    "$$S_t = S_0 - \\eta\\,\\int_0^t\\,v_s\\,e^{-\\rho\\,(t-s)}\\,ds + \\int_0^t\\,\\sigma\\,dZ_s$$\n",
    "\n",
    "with $v_t=-\\dot x_t$.\n",
    "\n",
    "- Market impact decays exponentially, *i.e.*, $G(\\tau) = e^{-\\rho\\tau}$ \n",
    "\n",
    "- Instantaneous market impact is linear in the rate of trading, $h(v) = -\\eta v$.\n",
    "\n",
    "\n",
    "The expected cost of trading becomes:\n",
    "$$\\mathcal{C} =\\eta\\,\\int_0^T\\int_0^t\\,{v}_s\\,e^{-\\rho\\,(t-s)}\\,ds\\, v_tdt$$\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### The Obizhaeva and Wang average price path\n",
    "<h2><img src=\"http://mfe.baruch.cuny.edu/wp-content/uploads/2015/04/ObizhaevaWang.png\" align = \"center\" width=500></h2>\n",
    "Figure 1: The Obizhaeva Wang average price path: higher $\\rho$ in pink; lower $\\rho$ in brown."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Obizhaeva Wang order book process\n",
    "<h2><img src=\"http://mfe.baruch.cuny.edu/wp-content/uploads/2015/04/BuziosBookOW.png\" align = \"center\" width=550></h2>\n",
    "When a trade of size $\\xi$ is placed at time $t$,\n",
    "\n",
    "\\begin{eqnarray*}\n",
    " E_t &\\mapsto& E_{t+}=E_t+\\xi\\\\\n",
    "D_t=\\eta\\,E_t &\\mapsto&\n",
    "D_{t+}=\\eta\\,E_{t+}=\\eta\\,\\left(E_{t}+\\xi \\right)\\end{eqnarray*}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "The Euler-Lagrange equation [(2)](#eq:intEL-TH) in this case reads:\n",
    "\n",
    "<a name=\"eq:intEL\"></a>(2')\n",
    "$$\n",
    "- \\eta \\int_t^T\\,v_s\\,e^{-\\rho\\,(s-t)}\\,ds - \\eta \\int_0^t\\,v_s\\,e^{-\\rho\\,(t-s)}\\,ds  = \\lambda.\n",
    "$$\n",
    "\n",
    "[(2')](#eq:intEL) may be rewritten as\n",
    "\n",
    "$$\\int_0^T\\,v_s\\,e^{-\\rho\\,|t-s|}\\,ds=-\\frac\\lambda\\eta$$\n",
    "\n",
    "which is a Fredholm integral\n",
    "equation of the first kind (see [Gatheral, Schied and Slynko]<sup id=\"cite_ref-GatheralSchiedSlynko\" class=\"reference\"><a href=\"#cite_note-GatheralSchiedSlynko\"><span>[</span>5<span>]</span></a></sup>)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "Now substitute \n",
    "\n",
    "$$v_s = A \\delta(s) + A \\rho + A \\delta(s-T),$$ \n",
    "\n",
    "where $A$ is a (to be determined) constant, into [(2')](#eq:intEL) to obtain\n",
    "\n",
    "$$\n",
    "A e^{-\\rho\\,t} + A \\left(1-e^{-\\rho\\,t}\\right) + 2A = -\\frac\\lambda\\eta\n",
    "\\quad \\Longrightarrow \\quad \\lambda = -3 A \\eta.\n",
    "$$\n",
    "\n",
    "Moreover, from the constraint $\\int_0^T v_t dt = X$,\n",
    "\n",
    "$$\n",
    "\\int_0^T v_t dt = 2 A + A \\rho T = X \\quad \\Longrightarrow \\quad A = \\frac X{2 + \\rho T}. \n",
    "$$\n",
    "\n",
    "The optimal strategy consists of a block trade at time $t=0$, continuous\n",
    "trading at the rate $\\rho$ over the interval $(0,T)$ and another block\n",
    "trade at time $t=T$."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "Consider the volume impact process $E_t$. The initial block-trade causes\n",
    "\n",
    "$$0=E_0 \\mapsto E_{0+} = A$$\n",
    "\n",
    "According to the assumptions of the model,\n",
    "the volume impact process reverts exponentially so\n",
    "\n",
    "$$E_t=E_{0+}\\,e^{-\\rho\\,t} + A \\rho\\,\\int_0^t\\,e^{-\\rho\\,(t-s)}\\,ds = A$$\n",
    "\n",
    "<span>*i.e.*</span> the volume impact process is constant when the\n",
    "trading strategy is optimal."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Optimality\n",
    "\n",
    "-   <span> Originally, [Obizhaeva and Wang]<sup id=\"cite_ref-ObizhaevaWang\" class=\"reference\"><a href=\"#cite_note-ObizhaevaWang\"><span>[</span>7<span>]</span></a></sup> derived their solution in discrete\n",
    "    time by explicitly solving the HJB equation. </span>\n",
    "\n",
    "\n",
    "-   The observation of [Predoiu, Shaikhet and Shreve]<sup id=\"cite_ref-PredoiuShaikhetShreve\" class=\"reference\"><a href=\"#cite_note-PredoiuShaikhetShreve\"><span>[</span>8<span>]</span></a></sup> allows us to deduce that\n",
    "    the statically optimal solution we just derived is also dynamically\n",
    "    optimal.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### The model of Alfonsi, Fruth and Schied\n",
    "\n",
    "[Alfonsi, Fruth and Schied]<sup id=\"cite_ref-AlfonsiFruthSchied\" class=\"reference\"><a href=\"#cite_note-AlfonsiFruthSchied\"><span>[</span>2<span>]</span></a></sup> consider the following (AS) model of the order book:\n",
    "\n",
    "-   <span>There is a continuous (in general nonlinear) density of orders\n",
    "    $f(x)$ above some martingale ask price $A_t$. The cumulative density\n",
    "    of orders up to price level $x$ is given by\n",
    "    \n",
    "    $$F(x):=\\int_0^x\\,f(y)\\,dy$$</span>\n",
    "\n",
    "\n",
    "-   <span>Executions eat into the order book (*i.e.* executions are with\n",
    "    market orders).</span>\n",
    "\n",
    "\n",
    "-   A purchase of $\\xi$ shares at time $t$ causes the ask price to\n",
    "    increase from $A_t+D_t$ to $A_t +D_{t+}$ with\n",
    "    \n",
    "    $$\\xi=\\int_{D_t}^{D_{t+}}\\,f(x)\\,dx=F(D_{t+})-F(D_{t})$$\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Schematic of the model\n",
    "<h2><img src=\"http://mfe.baruch.cuny.edu/wp-content/uploads/2015/04/BuziosASbook.png\" align = \"center\" width=550></h2>\n",
    "When a trade of size $\\xi$ is placed at time $t$,\n",
    "\n",
    "\\begin{eqnarray*}\n",
    " E_t &\\mapsto& E_{t+}=E_t+\\xi\\\\\n",
    "D_t=F^{-1}(E_t) &\\mapsto&\n",
    "D_{t+}=F^{-1}(E_{t+})=F^{-1}(E_{t}+\\xi)\\end{eqnarray*}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Optimal liquidation strategy in the AS model\n",
    "\n",
    "The cost of trade execution in the AS model is given by:\n",
    "\n",
    "<a name=\"eq:asCost2\"></a>(3)\n",
    "$$\\mathcal{C}=\\int_0^T\\,v_t\\,F^{-1}(E_t)\\,dt+\\sum_{t\\le T}\\,\\left[H(E_{t+})-H(E_{t})\\right]$$\n",
    "\n",
    "where $$E_t = \\int_0^t\\,v_s\\,e^{-\\rho\\,(t-s)}\\,ds$$ is the volume impact\n",
    "process and $$H(x)=\\int_0^x\\,F^{-1}(x)\\,dx$$ gives the cost of executing\n",
    "an instantaneous block trade of size $x$."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "Consider the ansatz $v_t=\\xi_0\\,\\delta(t)+\\xi_0\\,\\rho+\\xi_T\\delta(T-t)$.\n",
    "For $t \\in (0,T)$, we have $\n",
    "E_t=E_0=\\xi_0\n",
    "$, a constant. With this choice of $u_t$, we would have\n",
    "\n",
    "\\begin{eqnarray*}\n",
    "\\mathcal{C}(X)&=&F^{-1}(\\xi_0)\\,\\int_0^T\\,v_t\\,dt+\\left[H(E_{0^+})-H(E_{0})\\right]+\\left[H(E_{T})-H(E_{T^-})\\right]\\\\\n",
    "&=&F^{-1}(\\xi_0)\\,\\xi_0\\,\\rho\\,T+H(\\xi_0)+\\left[H(\\xi_0+\\xi_T)-H(\\xi_0)\\right]\\\\\n",
    "&=&F^{-1}(\\xi_0)\\,\\xi_0\\,\\rho\\,T+H(X-\\rho\\,\\xi_0\\,T)\\end{eqnarray*}\n",
    "\n",
    "Differentiating this last expression gives us the condition satisfied by\n",
    "the optimal choice of $\\xi_0$:\n",
    "\n",
    "$$F^{-1}(X-\\rho\\,\\xi_0\\,T)=F^{-1}(\\xi_0)+{F^{-1}}'(\\xi_0)\\,\\xi_0$$\n",
    "\n",
    "or\n",
    "equivalently\n",
    "\n",
    "$$F^{-1}(\\xi_0+\\xi_T)=F^{-1}(\\xi_0)+{F^{-1}}'(\\xi_0)\\,\\xi_0$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "Functionally differentiating $\\mathcal{C} $ with respect to $u_t$ gives\n",
    "\n",
    "<a name=\"eq:intEL_AS\"></a>(4)\n",
    "\\begin{eqnarray*}\n",
    "\\frac{\\delta \\mathcal{C}}{\\delta u_t}&=&F^{-1}(E_t)+\\int_t^T\\,u_s\\,{F^{-1}}'\\left(E_s\\right)\\,\\frac{\\delta E_s}{ \\delta u_t}\\,ds\\nonumber\\\\\n",
    "&=&F^{-1}(E_t)+\\int_t^T\\,u_s\\,{F^{-1}}'\\left(E_s\\right)\\,e^{-\\rho\\,(s-t)}\\,ds\n",
    "\\end{eqnarray*}\n",
    "\n",
    "The first term in [(4)](#eq:intEL_AS) represents the marginal cost of new\n",
    "quantity at time $t$ and the second term represents the marginal extra\n",
    "cost of future trading.\n",
    "\n",
    "With our ansatz, and a careful limiting argument, we obtain\n",
    "\n",
    "\\begin{eqnarray*}\n",
    "\\frac{\\delta \\mathcal{C}}{\\delta u_t}\n",
    "&=&F^{-1}(\\xi_0)+\\xi_0\\,{F^{-1}}'\\left(\\xi_0\\right)\\,\\left[1-e^{-\\rho\\,(T-t)}\\right] \n",
    "+ e^{-\\rho\\,(T-t)}\\,\\left[F^{-1}(\\xi_T+\\xi_0)-F^{-1}(\\xi_0)\\right]\n",
    "\\end{eqnarray*}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "Imposing our earlier condition on $\\xi_T$ gives\n",
    "\n",
    "\\begin{eqnarray*}\n",
    "\\frac{\\delta \\mathcal{C}}{\\delta u_t}&=&F^{-1}(\\xi_0)+\\xi_0\\,{F^{-1}}'\\left(\\xi_0\\right)\\,\\left[1-e^{-\\rho\\,(T-t)}\\right] + e^{-\\rho\\,(T-t)}\\,\\xi_0\\,{F^{-1}}'\\left(\\xi_0\\right)\\\\\n",
    "&=&F^{-1}(\\xi_0)+\\xi_0\\,{F^{-1}}'\\left(\\xi_0\\right)\\end{eqnarray*}\n",
    "\n",
    "which is constant, demonstrating (static) optimality.\n",
    "\n",
    "####<font color=\"red\"><span>Example</span>\n",
    "  \n",
    "<font color=\"red\">\n",
    "With $F^{-1}(x)=\\sqrt{x}$,\n",
    "$$\\sqrt{\\xi_0+\\xi_T}=F^{-1}(\\xi_0+\\xi_T)=F^{-1}(\\xi_0)+{F^{-1}}'(\\xi_0)\\,\\xi_0=\\sqrt{\\xi_0}+\\frac{1}{2}\\,\\sqrt{\\xi_0}$$\n",
    "which has the solution $\\xi_T=\\frac{5}{4}\\,\\xi_0$."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Generalization\n",
    "\n",
    "[Weiss]<sup id=\"cite_ref-Weiss\" class=\"reference\"><a href=\"#cite_note-Weiss\"><span>[</span>9<span>]</span></a></sup> and then [Predoiu, Shaikhet and Shreve]<sup id=\"cite_ref-PredoiuShaikhetShreve\" class=\"reference\"><a href=\"#cite_note-PredoiuShaikhetShreve\"><span>[</span>8<span>]</span></a></sup> have shown that the bucket-shaped\n",
    "strategy is optimal under more general conditions than exponential\n",
    "resiliency. Specifically, if resiliency is a function of $E_t$ (or\n",
    "equivalently $D_t$) only, the optimal strategy has a block trades at\n",
    "inception and completion and continuous trading at a constant rate\n",
    "in-between.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Optimality and price manipulation\n",
    "\n",
    "-   <span>For all of the models considered so far, there was an optimal\n",
    "    strategy.</span>\n",
    "\n",
    "\n",
    "-   <span>The optimal strategy always involved trades of the same sign.\n",
    "    So no sells in a buy program, no buys in a sell program.</span>\n",
    "\n",
    "\n",
    "-   <span>Recall that [Gatheral]<sup id=\"cite_ref-Gatheral\" class=\"reference\"><a href=\"#cite_note-Gatheral\"><span>[</span>4<span>]</span></a></sup> showed that we can write down models for\n",
    "    which price manipulation is possible.</span>\n",
    "\n",
    "    -   <span>For example, square root price impact with exponential\n",
    "        decay admits price manipulation.</span>\n",
    "\n",
    "\n",
    "-   <span>In such cases, a round-trip trade can generate cash on\n",
    "    average.</span>\n",
    "\n",
    "    -   <span>You would want to repeat such a trade over and\n",
    "        over.</span>\n",
    "\n",
    "    -   <span>There would be no optimal strategy.</span>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Linear transient market impact\n",
    "\n",
    "Recall Gatheral's transient impact model assumed in [Gatheral]<sup id=\"cite_ref-Gatheral\" class=\"reference\"><a href=\"#cite_note-Gatheral\"><span>[</span>4<span>]</span></a></sup> \n",
    "\n",
    "$$S_t=S_0+\\int_0^t\\,h(v_s)\\,G(t-s)\\,ds+\\text{ noise/zero mean martingale}$$\n",
    "\n",
    "In\n",
    "[Gatheral, Schied and Slynko]<sup id=\"cite_ref-GatheralSchiedSlynko\" class=\"reference\"><a href=\"#cite_note-GatheralSchiedSlynko\"><span>[</span>5<span>]</span></a></sup>, this model is on the one hand extended to\n",
    "explicitly include discrete optimal strategies and on the other hand\n",
    "restricted to the case of linear market impact, $h(v) = \\eta v$. When the admissible\n",
    "strategy $x$ is used, the price $S_t$ is given by\n",
    "\n",
    "<a name=\"eq:ModelEquation\"></a>(5)\n",
    "$$S_t = S_0 + \\eta \\int_{\\{s<t\\}}{G}(t-s)\\,dx_s + \\mbox{ martingale},$$\n",
    "\n",
    "and the expected cost of liquidation is given by\n",
    "\n",
    "<a name=\"eq:quadraticform\"></a>(6)\n",
    "$$\\mathcal{C} (x):=\\frac{\\eta}{2}\\,\\int_0^T\\int_0^T {G}(|t-s|)\\,dx_s\\,dx_t.$$\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Condition for no price manipulation\n",
    "\n",
    "<span>\n",
    "#### <font color=\"blue\">Definition (Huberman and Stanzl)\n",
    "<font color=\"blue\">\n",
    "\n",
    "A *round\n",
    "trip* is an admissible strategy with $x_0=x_T$. A *price manipulation\n",
    "strategy* is a round trip with strictly negative expected costs.</span>\n",
    "\n",
    "#### <font color=\"red\">Theorem (Bochner)\n",
    "<font color=\"red\"><span>$\\mathcal{C} (x)\\ge0$ for all admissible\n",
    "strategies $x$ if and only if ${G}(|\\cdot|)$ can be represented as the\n",
    "Fourier transform of a positive finite Borel measure $\\mu$ on\n",
    "$\\mathbb{R} $, i.e., $${G}(|\\tau|)=\\int e^{i \\,z\\,\\tau}\\,\\mu(dz).$$</span>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### First order condition\n",
    "\n",
    "For linear market impact, the Euler-Lagrange equation [(2)](#eq:intEL-TH) reduces to \n",
    "\n",
    "$$\\int_0^T {G}(|t-s|)\\,dx_s =\\lambda\\qquad\\text{for all $t\\in[0,T] $.}$$\n",
    "\n",
    "Moreover, we have\n",
    "\n",
    "####<font color=\"red\">Theorem\n",
    "<font color=\"red\">\n",
    "Suppose that ${G}$ is positive definite. Then $x^*$\n",
    "minimizes $\\mathcal{C} (\\cdot)$ if and only if there is a constant\n",
    "$\\lambda$ such that $x^*$ solves the generalized Fredholm integral\n",
    "equation\n",
    "\n",
    "<a name=\"eq:Fredholm\"></a>(7)\n",
    "$$\\int_0^T {G}(|t-s|)\\,dx^*_s =\\lambda\\qquad\\text{for all $t\\in[0,T] $.}$$\n",
    "\n",
    "In this case, $\\mathcal{C} (x^*)=\\frac{1}{2}\\,\\lambda \\,X$. In\n",
    "particular, $\\lambda$ must be nonzero as soon as ${G}$ is strictly\n",
    "positive definite and $X\\neq0$.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Transaction-triggered price manipulation\n",
    "\n",
    "#### <font color=\"blue\"> Definition (Alfonsi, Schied, Slynko (2009))\n",
    "A market impact model admits\n",
    "*transaction-triggered price manipulation* if the expected costs of a\n",
    "sell (buy) program can be decreased by intermediate buy (sell) trades.\n",
    "</font>\n",
    "\n",
    "As discussed in [Alfonsi, Schied and Slynko]<sup id=\"cite_ref-AlfonsiSchiedSlynko\" class=\"reference\"><a href=\"#cite_note-AlfonsiSchiedSlynko\"><span>[</span>3<span>]</span></a></sup>, transaction-triggered price\n",
    "manipulation can be regarded as an additional model irregularity that\n",
    "should be excluded. Transaction-triggered price manipulation can exist\n",
    "in models that do not admit standard price manipulation in the sense of\n",
    "Huberman and Stanzl definition.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Condition for no transaction-triggered price manipulation\n",
    "\n",
    "\n",
    "<span>\n",
    "#### <font color=\"red\">Theorem\n",
    "\n",
    "<font color=\"red\">\n",
    "Suppose that the decay kernel ${G}(\\cdot)$ is convex,\n",
    "satisfies $\\int_0^1{G}(t)\\,dt<\\infty$ and that the set of admissible\n",
    "strategies is nonempty. Then there exists a unique admissible optimal\n",
    "strategy $x^*$. Moreover, $x^*_t$ is a monotone function of $t$, and so\n",
    "there is no transaction-triggered price manipulation.\n",
    "</span>\n",
    "\n",
    "<span>\n",
    "#### <font color=\"red\">Remark\n",
    "\n",
    "<font color=\"red\">\n",
    "If ${G}$ is not convex in a neighborhood of zero, there is\n",
    "transaction-triggered price manipulation.\n",
    "</span>\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### An instructive example\n",
    "\n",
    "We solve a discretized version of the Fredholm equation (with 512 time\n",
    "points) for two similar decay kernels:\n",
    "\n",
    "$$G_1(\\tau)=\\frac{1}{(1+t)^2};\\qquad G_2(\\tau)=\\frac{1}{1+t^2}$$\n",
    "\n",
    "<h2><img src=\"http://mfe.baruch.cuny.edu/wp-content/uploads/2015/04/PetitDejeunerG.png\" align = \"center\" width=500></h2>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "$G_1(\\cdot)$ is convex, but $G_2(\\cdot)$ is concave near $\\tau=0$ so\n",
    "there should be a unique optimal strategy with $G_1(\\cdot)$ as a choice\n",
    "of kernel but there should be transaction-triggered price manipulation\n",
    "with $G_2(\\cdot)$ as the choice of decay kernel."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Schematic of numerical solutions of Fredholm equation\n",
    "\n",
    "$G_1(\\tau)=\\frac{1}{(1+\\tau)^2}$\n",
    "<h2><img src=\"http://mfe.baruch.cuny.edu/wp-content/uploads/2015/04/TorontoComputationalPolynomial.png\" align = \"center\" width=300></h2>\n",
    "\n",
    "$G_2(\\tau)=\\frac{1}{1+\\tau^2}$\n",
    "<h2><img src=\"http://mfe.baruch.cuny.edu/wp-content/uploads/2015/04/TorontoComputationalTTM.png\" align = \"center\" width=300></h2>\n",
    "\n",
    "Figure 2: In the top figure, we observe block trades at $t=0$ and $t=1$ with continuous (nonconstant) trading in $(0,1)$. In the bottom figure, we see numerical evidence that the optimal strategy does not exist."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "Now we give some examples of the optimal strategy with choices of kernel\n",
    "that preclude transaction-triggered price manipulation."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Example I: Linear market impact with exponential decay\n",
    "\n",
    "$G(\\tau)=e^{-\\rho\\,\\tau}$ and the optimal strategy $u(s)$ solves\n",
    "\n",
    "$$\\int_0^T\\,u(s)e^{-\\rho\\,|t-s|}\\,ds=\\text{const.}$$\n",
    "\n",
    "We already derived\n",
    "the solution which is\n",
    "\n",
    "$$u(s)=A\\,\\left\\{\\delta(t)+\\rho+\\delta(T-t)\\right\\}$$\n",
    "\n",
    "The normalizing\n",
    "factor $A$ is given by\n",
    "\n",
    "$$\\int_0^T\\,u(t)\\,dt=X=A\\, \\left(2+\\rho\\,T\\right)$$\n",
    "\n",
    "The optimal strategy\n",
    "consists of block trades at $t=0$ and $t=T$ and continuous trading at\n",
    "the constant rate $\\rho$ between these two times.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Schematic of optimal strategy\n",
    "\n",
    "The optimal strategy with $\\rho=0.1$ and $T=1$\n",
    "<h2><img src=\"http://mfe.baruch.cuny.edu/wp-content/uploads/2015/04/Algo2010Exponential.png\" align = \"center\" width=500></h2>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Example II: Linear market impact with power-law decay\n",
    "\n",
    "$G(\\tau)=\\tau^{-\\gamma}$ and the optimal strategy $u(s)$ solves\n",
    "\n",
    "$$\\int_0^T\\,\\frac{u(s)}{|t-s|^\\gamma}\\,ds=\\text{const.}$$\n",
    "\n",
    "The solution\n",
    "is \n",
    "\n",
    "$$u(s)=\\frac{A}{\\left[s\\,(T-s)\\right]^{(1-\\gamma)/2}}$$\n",
    "\n",
    "The\n",
    "normalizing factor $A$ is given by\n",
    "\n",
    "$$\\int_0^T\\,u(t)\\,dt=X=A\\, \\sqrt{\\pi }\\,\\left(\\frac{T}{2}\\right)^\\gamma \\,\\frac{ \\Gamma \\left(\n",
    "\\frac{1+\\gamma}{2}\\right)}{\\Gamma \\left(1+\\frac{\\gamma }{2}\\right)}$$\n",
    "\n",
    "The optimal strategy is absolutely continuous with no block trades.\n",
    "However, it is singular at $t=0$ and $t=T$.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Schematic of optimal strategy\n",
    "\n",
    "The red line is a plot of the optimal strategy with $T=1$ and\n",
    "$\\gamma=1/2$.\n",
    "<h2><img src=\"http://mfe.baruch.cuny.edu/wp-content/uploads/2015/04/Algo2010PowerLaw.png\" align = \"center\" width=500></h2>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Example III: Linear market impact with linear decay\n",
    "\n",
    "$G(\\tau)=(1-\\rho\\,\\tau)^+$ and the optimal strategy $u(s)$ solves\n",
    "\n",
    "$$\\int_0^T\\,{u(s)}\\,(1-\\rho\\,|t-s|)^+\\,ds=\\text{const.}$$\n",
    "\n",
    "Let\n",
    "$N:=\\lfloor{\\rho\\,T}\\rfloor$, the largest integer less than or equal to\n",
    "$\\rho\\,T$. Then\n",
    "\n",
    "$$u(s)=A\\,\\sum_{i =0}^ N\\,\\left(1-\\frac{i}{N+1}\\right)\\,\\left\\{\\delta\\left(s- \\frac{i}{\\rho}\\right)+\\delta\\left(T-s- \\frac{i}{\\rho}\\right)\\right\\}$$\n",
    "\n",
    "The normalizing factor $A$ is given by\n",
    "\n",
    "$$\\int_0^T\\,u(t)\\,dt=X=A\\, \\sum_{i =0}^ N\\,2\\,\\left(1-\\frac{i}{N+1}\\right)=A\\,(2 + N)$$\n",
    "\n",
    "The optimal strategy consists only of block trades with no trading\n",
    "between blocks.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Schematic of optimal strategy\n",
    "\n",
    "Positions and relative sizes of the block trades in the optimal strategy\n",
    "with $\\rho=1$ and $T=5.2$ (so $N=\\lfloor\\rho\\,T\\rfloor=5$).\n",
    "<h2><img src=\"http://mfe.baruch.cuny.edu/wp-content/uploads/2015/04/Algo2010Linear.png\" align = \"center\" width=500></h2>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### When is the optimal strategy bucket-shaped?\n",
    "\n",
    "-   For which nonincreasing convex decay kernels $G$ does the optimal\n",
    "    execution strategy have singular components only at $t=0$ and $t=T$\n",
    "    with absolutely continuous trading on the interval $(0,T)$?\n",
    "\n",
    "    -   This question is answered in Corollary 1 of [Alfonsi and Schied]<sup id=\"cite_ref-AlfonsiSchied\" class=\"reference\"><a href=\"#cite_note-AlfonsiSchied\"><span>[</span>1<span>]</span></a></sup>.\n",
    "\n",
    "<font color=\"red\">\n",
    "#### Corollary\n",
    "Suppose that $G$ is completely monotone with\n",
    "$G''(0+):=\\lim_{t \\downarrow 0} G''(t) < \\infty$. Then the capacitary\n",
    "measure $\\mu^\\star$ has two Dirac components at $t=0$ and $t=T$ and has\n",
    "a continuous Lebesgue density on $(0,T)$.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Completely monotone functions\n",
    "\n",
    "#### <font color=\"blue\"> Definition\n",
    "$G$ is completely monotone if $G$ belongs to $C^\\infty((0,\\infty))$ and\n",
    "$(-1)^nG^{(n)}$ is nonnegative in $(0,\\infty)$ for $n \\in \\mathbb N$.\n",
    "</font>\n",
    "\n",
    "#### <font color=red> Theorem (Hausdorff–Bernstein–Widder)\n",
    "G is completely monotone if and only it is\n",
    "the Laplace transform of a Borel probability measure $\\lambda$ on\n",
    "$\\mathbb{R}+$:\n",
    "\n",
    "$$G(t) = \\int \\,e^{-\\rho\\,t}\\,\\lambda(d\\rho), \\quad t \\geq 0.$$\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Examples of completely monotone functions\n",
    "\n",
    "-   Examples of completely monotone functions are\n",
    "\n",
    "    \\begin{eqnarray*}\n",
    "    G_1(\\tau)&=&\\frac{1}{(1+\\tau)^\\gamma}\\\\\n",
    "    G_2(\\tau)&=&\\sum_{i=1}^d\\,\\lambda_i\\,e^{-\\rho_i\\,\\tau} \\text{ with } \\sum_{i=1}^d\\,\\lambda_i=1 \\text{ and } \\,\\lambda_i,\\,\\rho_i\\geq0\\end{eqnarray*}\n",
    "\n",
    "\n",
    "-   Roughly speaking then, if the decay kernel looks like a sum of\n",
    "    exponential decay terms, the optimal strategy under linear transient\n",
    "    impact consists of a block at the beginning, a block at the end and\n",
    "    continuous trading in-between.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Examples of functions that are not completely monotone\n",
    "\n",
    "-   Examples of these include\n",
    "\n",
    "    \\begin{eqnarray*}\n",
    "    G_3(\\tau)&=&\\frac{1}{1+\\tau^2}\\\\\n",
    "    G_4(\\tau)&=&(1-\\rho\\,\\tau)^+\\end{eqnarray*}\n",
    "\n",
    "\n",
    "-   $G_3(\\cdot)$ is not monotone because $G''(\\tau)$ changes sign.\n",
    "\n",
    "-   $G_4(\\cdot)$ is not monotone because it is not smooth (it has a\n",
    "    discontinuous first derivative).\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Price-manipulation with nonlinear market impact\n",
    "\n",
    "\n",
    "#### <font color=\"red\"> Proposition ([Gatheral, Schied and Slynko: Exponential resilience]<sup id=\"cite_ref-GatheralSchiedSlynko2\" class=\"reference\"><a href=\"#cite_note-GatheralSchiedSlynko2\"><span>[</span>6<span>]</span></a></sup>) \n",
    "\n",
    "Assuming the price process\n",
    "$$S_t=S_0+\\int_0^t\\,h(v_s)\\,G(t-s)\\,ds+\\text{ noise},$$ consider a model\n",
    "with a general nonlinear instantaneous market impact function $h(\\cdot)$\n",
    "and a nonincreasing decay kernel $G(t)$ with\n",
    "$G(0) := \\lim_{t\\downarrow 0} G(t) <\\infty$. Then, such a model admits\n",
    "price manipulation.\n",
    "</font>\n",
    "\n",
    "\n",
    "-   The proof follows closely the proof for the special case of\n",
    "    exponential decay of market impact that we presented in Lecture 8.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Nonlinear transient market impact\n",
    "\n",
    "-   We know that the reaction of market price to quantity is in general\n",
    "    nonlinear.\n",
    "\n",
    "    -   Concave for small quantity and convex for large quantity.\n",
    "\n",
    "\n",
    "-   We also know that the market price reverts after completion of a\n",
    "    meta-order (using VWAP say).\n",
    "\n",
    "\n",
    "-   What is the optimal strategy under nonlinear transient market\n",
    "    impact?\n",
    "\n",
    "    -   The answer is that we don’t know...\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### A nonlinear transient market impact model\n",
    "\n",
    "Once again, the price process assumed in [Gatheral]<sup id=\"cite_ref-Gatheral\" class=\"reference\"><a href=\"#cite_note-Gatheral\"><span>[</span>4<span>]</span></a></sup> is\n",
    "\n",
    "<a name=\"eq:GatheralProcess\"></a>(8)\n",
    "$$S_t=S_0+\\int_0^t\\,h(v_s)\\,G(t-s)\\,ds+\\text{ noise}$$\n",
    "\n",
    "-   The instantaneous impact of a trade at time $s$ is given by\n",
    "    $h(v_s)$, some function of the rate of trading.\n",
    "\n",
    "-   A proportion $G(t-s)$ of this initial impact is still felt at time\n",
    "    $t>s$.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### The square-root model\n",
    "\n",
    "Consider the following special case of [(8)](#eq:GatheralProcess) with\n",
    "$h(v)=\\frac  3 4 \\sigma\\,\\sqrt{{v}/{V}}$ and $G(\\tau)=1/\\sqrt{\\tau}$:\n",
    "\n",
    "<a name=\"eq:sqrt\"></a>(9)\n",
    "$$S_t=S_0+\\frac 3 4 \\,\\sigma\\, \\int_0^t\\,\\sqrt{ \\frac{v_s} V}\\,\\frac {ds}{\\sqrt{t-s}}+\\text{ noise}$$\n",
    "\n",
    "which we will call the <span>*square-root process*</span>.\n",
    "\n",
    "It is easy to verify that under the square-root process, the expected\n",
    "cost of a VWAP execution is given by the square-root formula for market\n",
    "impact:\n",
    "\n",
    "<a name=\"eq:sqrtFormula\"></a>(10)\n",
    "$$\\frac{\\mathcal{C} }{X}=\\sigma \\,\\sqrt{\\frac X V}$$\n",
    "\n",
    "-   Of course, that doesn’t mean that the square-root process is the\n",
    "    true underlying process!\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Costing an interval VWAP strategy with square-root decay\n",
    "\n",
    "Suppose we partition the interval $\\{0,T\\}$ into $m$ subintervals\n",
    "$\\{0,t_1,t_2,..,t_{m-1},t_m=T\\}$ and suppose further that our rate of\n",
    "trading $v_t={\\dot x}_t$ is constant over each subinterval.\n",
    "\n",
    "The contribution to the cost from trading in the first subinterval is\n",
    "simply\n",
    "\n",
    "\\begin{eqnarray*}\n",
    "&&\\frac{x_1}{t_1}\\,h(v_1)\\,\\int_0^{t_1}\\,dt\\,\\int_0^{t}\\,\\frac{1}{\\sqrt{t-s}}\\,ds\\\\\n",
    "&=&2\\,\\frac{x_1}{t_1}\\,h(v_1)\\,\\int_0^{t_1}\\,dt\\,{\\sqrt{t}}\\\\\n",
    "&=&\\frac{4}{3}\\,x_1\\,h(v_1)\\,\\sqrt{t_1}\\end{eqnarray*}\n",
    "\n",
    "where $x_1$ is the number of shares liquidated in the first interval.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Matrix elements\n",
    "\n",
    "In general, the $i$th self-interaction term is given by\n",
    "\n",
    "$$C_{ii}=\\frac{x_i}{t_{i}-t_{i-1}}\\,h(v_i)\\,\\int_{t_{i-1}}^{t_i}\\,dt\\,\\int_{t_{i-1}}^{t}\\,\\frac{1}{\\sqrt{t-s}}\\,ds=\n",
    "\\frac{4}{3}\\,x_i\\,h(v_i)\\,\\sqrt{t_i-t_{i-1}}$$\n",
    "\n",
    "The contribution to the cost from trading in the $j$th subinterval\n",
    "related to trading in the $i$th subinterval with $i<j$ is given by\n",
    "\n",
    "\\begin{eqnarray*}\n",
    "C_{ji}&=&\\frac{x_j}{t_{j}-t_{j-1}}\\,h(v_i)\\,\\int_{t_{j-1}}^{t_j}\\,dt\\,\\int_{t_{i-1}}^{t_i}\\,\\frac{1}{\\sqrt{t-s}}\\,ds\\\\&=&\n",
    "\\frac{4}{3}\\,x_j\\,h(v_i)\\,\\frac{\\left(t_{j}-t_{i-1}\\right)^{3/2}\n",
    "-\\left(t_{j}-t_{i}\\right)^{3/2}\n",
    "-\\left(t_{j-1}-t_{i-1}\\right)^{3/2}\n",
    "+\\left(t_{j-1}-t_{i}\\right)^{3/2}\n",
    "}{t_{j}-t_{j-1}}\\end{eqnarray*}\n",
    "\n",
    "where $x_j$ is the number of shares liquidated in the $j$th\n",
    "sub-interval.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Cost of liquidation\n",
    "\n",
    "The cost of liquidation is then given by\n",
    "\n",
    "<a name=\"eq:exactCost\"></a>(11)\n",
    "$$\\mathcal{C} =\\sum_{j=1}^m\\,C_{jj}+\\sum_{i< j}^m\\,C_{ji}$$\n",
    "\n",
    "-   For fixed $m$, we can then minimize $\\mathcal{C} $ with respect to\n",
    "    (for example) the $x_i$ and the positions of the $t_i$.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### The optimal strategy under the square-root process\n",
    "\n",
    "-   It turns out that because $h(\\cdot)$ is concave, an optimal strategy\n",
    "    does not exist in the square-root model.\n",
    "\n",
    "    -   It is possible to drive the expected cost of trading to zero by\n",
    "        increasing the number of slices and decreasing the duration of\n",
    "        each slice.\n",
    "\n",
    "    -   To be more realistic, $h(v)$ must be convex for large $v$ and in\n",
    "        this case, an optimal strategy does exist that involves trading\n",
    "        in bursts, usually more than two.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Price path in the square-root model\n",
    "\n",
    "Figure 2: The expected path of the market price during and after execution of a VWAP order in the square-root model.\n",
    "<h2><img src=\"http://mfe.baruch.cuny.edu/wp-content/uploads/2015/04/PathSqrt.png\" align = \"center\" width=500></h2>\n",
    "\n",
    "-   The optimal strategy does not exist in this model.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Potential cost savings from optimal scheduling\n",
    "\n",
    "-   To estimate potential savings from optimal scheduling, assume that\n",
    "    the square-root process [(9)](#eq:sqrt) is correct and consider a one-day order to\n",
    "    sell 540,000 shares of IBM.\n",
    "\n",
    "    -   Daily volatility is assumed to be $2\\%$ and daily volume to be 6\n",
    "        million shares.\n",
    "\n",
    "    -   We consider liquidation starting at 09:45 and ending at 15:45\n",
    "        with child orders lasting 15 minutes.\n",
    "\n",
    "-   Because we are not confident in the square-root model for high\n",
    "    volume fractions, we constrain volume fraction to be no greater than\n",
    "    $25\\%$.\n",
    "\n",
    "-   We compare the costs of VWAP, a two-slice bucket-like strategy and a\n",
    "    quasi-optimal strategy that consists of seven roughly equal slices.\n",
    "\n",
    "    -   The quasi-optimal strategy consists of bursts of trading\n",
    "        separated by periods of non-trading.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Stock trading schedules\n",
    "<h2><img src=\"http://mfe.baruch.cuny.edu/wp-content/uploads/2015/04/JOIM2011schedules.png\" align = \"center\" width=600></h2>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Summary I\n",
    "\n",
    "-   <span>The optimal trading strategy depends on the model.</span>\n",
    "\n",
    "    -   <span>For Almgren-Chriss style models, if the price of risk is\n",
    "        zero, the minimal cost strategy is VWAP.</span>\n",
    "\n",
    "    -   <span>In Alfonsi-Schied style models with resiliency that\n",
    "        depends only on the current spread, the minimal cost strategy is\n",
    "        to trade a block at inception, a block at completion and at a\n",
    "        constant rate in between.</span>\n",
    "\n",
    "    -   <span>More generally, if market impact is transient, the optimal\n",
    "        strategy involves bursts of trading; VWAP is never\n",
    "        optimal.</span>\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Summary II\n",
    "\n",
    "-   We can state sufficient conditions on the price process [(8)](#eq:GatheralProcess) for it to\n",
    "    make sense:\n",
    "\n",
    "    -   There is no transaction-triggered price manipulation if the\n",
    "        kernel $G(\\cdot)$ is convex. It would seem reasonable to also\n",
    "        require complete monotonicity.\n",
    "\n",
    "    -   If market impact is nonlinear, the kernel $G(\\cdot)$ must be\n",
    "        singular at $t=0$.\n",
    "\n",
    "    -   A nonlinear instantaneous market impact function $h(\\cdot)$ must\n",
    "        be convex for sufficiently high trading rates for an optimal\n",
    "        strategy to exist.\n",
    "\n",
    "-   Assuming square-root dynamics consistent with the square-root market\n",
    "    impact formula, we showed that large cost savings are possible by\n",
    "    optimizing the scheduling strategy.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### References\n",
    "\n",
    "<br />\n",
    "\n",
    "<div class=\"reflist\" style=\"list-style-type: decimal;\">\n",
    "\n",
    "<ol>\n",
    "\n",
    "  <li id=\"cite_note-AlfonsiSchied\"><span class=\"mw-cite-backlink\"><b><a href=\"#cite_ref-AlfonsiSchied\">^</a></b></span>\n",
    "  Capacitary measures for completely monotone kernels via singular\n",
    "control, Alexander Schied and Aurélien Alfonsi, <span>*SIAM Journal on\n",
    "Control and Optimization*</span> <span>**51**</span>(2) 1758–1780\n",
    "(2013).\n",
    "  </li>\n",
    "  \n",
    "  <li id=\"cite_note-AlfonsiFruthSchied\"><span class=\"mw-cite-backlink\"><b><a href=\"#cite_ref-AlfonsiFruthSchied\">^</a></b></span>\n",
    "  Aurélien Alfonsi, Antje Fruth and Alexander Schied, Optimal execution\n",
    "strategies in limit order books with general shape functions,\n",
    "<span>*Quantitative Finance*</span> <span>**10**</span>(2) 143–157\n",
    "(2010).\n",
    "  </li>\n",
    "  \n",
    "  <li id=\"cite_note-AlfonsiSchiedSlynko\"><span class=\"mw-cite-backlink\"><b><a href=\"#cite_ref-AlfonsiSchiedSlynko\">^</a></b></span>\n",
    "  Aurélien Alfonsi, Alexander Schied and Alla Slynko, Order book\n",
    "resilience, price manipulation, and the positive portfolio problem,\n",
    "<span>*SIAM Journal on Financial Mathematics*</span>\n",
    "<span>**3**</span>(1) 511–533 (2012).\n",
    "  </li>\n",
    "  \n",
    "  <li id=\"cite_note-Gatheral\"><span class=\"mw-cite-backlink\"><b><a href=\"#cite_ref-Gatheral\">^</a></b></span>\n",
    "  Jim Gatheral, No-dynamic-arbitrage and market impact,\n",
    "<span>*Quantitative Finance*</span> <span>**10**</span>(7) 749–759\n",
    "(2010).\n",
    "  </li>\n",
    "  \n",
    "  <li id=\"cite_note-GatheralSchiedSlynko\"><span class=\"mw-cite-backlink\"><b><a href=\"#cite_ref-GatheralSchiedSlynko\">^</a></b></span>\n",
    "  Jim Gatheral, Alexander Schied and Alla Slynko, Transient linear price\n",
    "impact and Fredholm integral equations, <span>*Mathematical\n",
    "Finance*</span> <span>**22**</span>, 445–474 (2012).\n",
    "  </li>\n",
    "  \n",
    "  <li id=\"cite_note-GatheralSchiedSlynko2\"><span class=\"mw-cite-backlink\"><b><a href=\"#cite_ref-GatheralSchiedSlynko2\">^</a></b></span>\n",
    "  Jim Gatheral, Alexander Schied and Alla Slynko, Exponential resilience\n",
    "and decay of market impact, <span>*Econophysics of Order-Driven\n",
    "Markets*</span>, Springer, 225–236 (2011).\n",
    "  </li>\n",
    "  \n",
    "  <li id=\"cite_note-ObizhaevaWang\"><span class=\"mw-cite-backlink\"><b><a href=\"#cite_ref-ObizhaevaWang\">^</a></b></span>\n",
    "  Anna Obizhaeva and Jiang Wang, Optimal trading strategy and\n",
    "supply/demand dynamics, <span>*Journal of Financial Markets*</span>\n",
    "<span>**16**</span>(1) 1–32 (2013).\n",
    "  </li>\n",
    "  \n",
    "  <li id=\"cite_note-PredoiuShaikhetShreve\"><span class=\"mw-cite-backlink\"><b><a href=\"#cite_ref-PredoiuShaikhetShreve\">^</a></b></span>\n",
    "  Silviu Predoiu, Gennady Shaikhet and Steven Shreve, Optimal execution in\n",
    "a general one-sided limit-order book, <span>*SIAM Journal on Financial\n",
    "Mathematics*</span> (2012).\n",
    "  </li>\n",
    "\n",
    "  <li id=\"cite_note-Weiss\"><span class=\"mw-cite-backlink\"><b><a href=\"#cite_ref-Weiss\">^</a></b></span>\n",
    "  Alexander Weiss, Executing large orders in a microscopic market model,\n",
    "arXiv (2009).\n",
    "  </li>\n",
    "  \n",
    "</ol>"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
